package com.airbat.prize.utils;

public class DeptUtil {

    public static String areaCodeCLeanZreo(String code){
        if (isNotBlank(code)){
            String areacode = addingZero(code,6);
            if (areacode.substring(0,6).equals("000000")){
                return "";
            }else if (areacode.substring(2,6).equals("0000")){
                return areacode.substring(0, 2);
            }else if (areacode.substring(4,6).equals("00")){
                return areacode.substring(0, 4);
            }else{
                return areacode;
            }
        }
        return "";
    }
    /**
     * 部门地区编码补零取前面x位
     * @param code
     * @param strLong
     * @return
     */
    public static String addingZero(String code, Integer strLong) {
        try {
            if (isBlank(code))
                return null;
            if (null == strLong || strLong < 1)
                return code;
            String zeroStr = "00000000000000000";
            if (zeroStr.length() < strLong) {
                for (int i = 0; zeroStr.length() < strLong && i < 5; i++) {
                    zeroStr += zeroStr;
                }
            }
            return (code + zeroStr).substring(0, strLong);
        } catch (Exception e) {
            return code;
        }
    }
    public static boolean isBlank(String str) {
        int strLen;
        if (str != null && (strLen = str.length()) != 0) {
            for (int i = 0; i < strLen; ++i) {
                if (!Character.isWhitespace(str.charAt(i))) {
                    return false;
                }
            }
            return true;
        } else {
            return true;
        }
    }
    public static boolean isNotBlank(String str) {
        return !isBlank(str);
    }
}
